package it.unibo.iss.domotica.generator;

import com.google.inject.Inject;
import it.unibo.iss.domotica.domoticDsl.Consumption;
import it.unibo.iss.domotica.domoticDsl.Elettrodomestico;
import it.unibo.iss.domotica.domoticDsl.Package;
import it.unibo.iss.domotica.domoticDsl.Properties;
import it.unibo.iss.domotica.domoticDsl.Sensor;
import it.unibo.iss.domotica.domoticDsl.System;
import it.unibo.iss.domotica.domoticDsl.Usage;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.xtext.generator.IFileSystemAccess;
import org.eclipse.xtext.generator.IGenerator;
import org.eclipse.xtext.naming.IQualifiedNameProvider;
import org.eclipse.xtext.xbase.lib.BooleanExtensions;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.StringExtensions;
import org.eclipse.xtext.xtend2.lib.ResourceExtensions;
import org.eclipse.xtext.xtend2.lib.StringConcatenation;

@SuppressWarnings("all")
public class DomoticDslGenerator implements IGenerator {
  
  @Inject
  private IQualifiedNameProvider nameProvider;
  
  public void doGenerate(final Resource resource, final IFileSystemAccess fsa) {
    Iterable<EObject> _allContentsIterable = ResourceExtensions.allContentsIterable(resource);
    Iterable<System> _filter = IterableExtensions.<System>filter(_allContentsIterable, it.unibo.iss.domotica.domoticDsl.System.class);
    for (final System s : _filter) {
      {
        Package _package = s.getPackage();
        String _name = _package.getName();
        String _string = _name.toString();
        String _replace = _string.replace(".", "/");
        String _operator_plus = StringExtensions.operator_plus(_replace, "/");
        final String packageName = _operator_plus;
        String _name_1 = s.getName();
        String _firstUpper = StringExtensions.toFirstUpper(_name_1);
        String _operator_plus_1 = StringExtensions.operator_plus(packageName, _firstUpper);
        String _operator_plus_2 = StringExtensions.operator_plus(_operator_plus_1, ".java");
        StringConcatenation _compile = this.compile(s);
        fsa.generateFile(_operator_plus_2, _compile);
      }
    }
  }
  
  public StringConcatenation compile(final System s) {
    StringConcatenation _builder = new StringConcatenation();
    {
      Package _package = s.getPackage();
      boolean _operator_notEquals = ObjectExtensions.operator_notEquals(_package, null);
      if (_operator_notEquals) {
        _builder.append("package ");
        Package _package_1 = s.getPackage();
        String _name = _package_1.getName();
        _builder.append(_name, "");
        _builder.append(";");
        _builder.newLineIfNotEmpty();
      }
    }
    _builder.newLine();
    _builder.append("import java.util.ArrayList;");
    _builder.newLine();
    _builder.append("import java.util.Properties;");
    _builder.newLine();
    _builder.append("import java.io.FileInputStream;");
    _builder.newLine();
    _builder.append("import java.io.FileNotFoundException;");
    _builder.newLine();
    _builder.append("import java.io.IOException;");
    _builder.newLine();
    _builder.append("import it.unibo.iss.domotica.edDomain.*;");
    _builder.newLine();
    _builder.newLine();
    _builder.append("public class ");
    String _name_1 = s.getName();
    String _firstUpper = StringExtensions.toFirstUpper(_name_1);
    _builder.append(_firstUpper, "");
    _builder.append("Model {");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("private ArrayList<IElettrodomestico> listEd = new ArrayList<IElettrodomestico>();");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("private ArrayList<ISensor> sensors = new ArrayList<ISensor>();");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("private String propertiesPath;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("private Properties prop = null;");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public ");
    String _name_2 = s.getName();
    String _firstUpper_1 = StringExtensions.toFirstUpper(_name_2);
    _builder.append(_firstUpper_1, "	");
    _builder.append("() {");
    _builder.newLineIfNotEmpty();
    {
      Properties _properties = s.getProperties();
      boolean _operator_notEquals_1 = ObjectExtensions.operator_notEquals(_properties, null);
      if (_operator_notEquals_1) {
        _builder.append("\t\t");
        _builder.append("propertiesPath = \"");
        Properties _properties_1 = s.getProperties();
        String _name_3 = _properties_1.getName();
        _builder.append(_name_3, "		");
        _builder.append("\";");
        _builder.newLineIfNotEmpty();} else {
        _builder.append("\t\t");
        _builder.append("propertiesPath = \"G:\\\\Documenti\\\\Universita\\\\Magistrale\\\\Ingegneria dei Sistemi Software M\\\\workspace\\\\domotica.scontrol\\\\src\\\\system.properties\";");
        _builder.newLine();
      }
    }
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public void setListEd(ArrayList<IElettrodomestico> listEd) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("this.listEd = listEd;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public ArrayList<IElettrodomestico> getListEd() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("return listEd;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public void setSensors(ArrayList<ISensor> sensors) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("this.sensors = sensors;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public ArrayList<ISensor> getSensors() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("return sensors;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public ArrayList<IElettrodomestico> createAppliances() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.newLine();
    {
      EList<Elettrodomestico> _elettrodomestico = s.getElettrodomestico();
      for(final Elettrodomestico e : _elettrodomestico) {
        _builder.append("\t\t");
        _builder.append("listEd.add(new Elettrodomestico(\"");
        String _name_4 = e.getName();
        _builder.append(_name_4, "		");
        _builder.append("\", CatUsage.");
        Usage _usage = e.getUsage();
        _builder.append(_usage, "		");
        _builder.append(" , CatConsumptionEnum.");
        Consumption _consumption = e.getConsumption();
        _builder.append(_consumption, "		");
        _builder.append("));");
        _builder.newLineIfNotEmpty();
      }
    }
    _builder.append("\t\t");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("return listEd;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public ArrayList<ISensor> createSensors() throws Exception {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.newLine();
    {
      EList<Sensor> _sensors = s.getSensors();
      for(final Sensor sensor : _sensors) {
        {
          boolean _operator_and = false;
          String _minConsumption = sensor.getMinConsumption();
          boolean _operator_notEquals_2 = ObjectExtensions.operator_notEquals(_minConsumption, null);
          if (!_operator_notEquals_2) {
            _operator_and = false;
          } else {
            String _maxConsumption = sensor.getMaxConsumption();
            boolean _operator_notEquals_3 = ObjectExtensions.operator_notEquals(_maxConsumption, null);
            _operator_and = BooleanExtensions.operator_and(_operator_notEquals_2, _operator_notEquals_3);
          }
          if (_operator_and) {
            _builder.append("\t\t");
            _builder.append("sensors.add(new Sensor(\"");
            Elettrodomestico _elettrodomestico_1 = sensor.getElettrodomestico();
            String _name_5 = _elettrodomestico_1.getName();
            _builder.append(_name_5, "		");
            _builder.append("\", ");
            String _minConsumption_1 = sensor.getMinConsumption();
            _builder.append(_minConsumption_1, "		");
            _builder.append(", ");
            String _maxConsumption_1 = sensor.getMaxConsumption();
            _builder.append(_maxConsumption_1, "		");
            _builder.append("));");
            _builder.newLineIfNotEmpty();} else {
            _builder.append("\t\t");
            _builder.append("sensors.add(new Sensor(\"");
            Elettrodomestico _elettrodomestico_2 = sensor.getElettrodomestico();
            String _name_6 = _elettrodomestico_2.getName();
            _builder.append(_name_6, "		");
            _builder.append("\", loadConsumFromProp(CatConsumptionEnum.");
            Elettrodomestico _elettrodomestico_3 = sensor.getElettrodomestico();
            Consumption _consumption_1 = _elettrodomestico_3.getConsumption();
            _builder.append(_consumption_1, "		");
            _builder.append(", 0), loadConsumFromProp(CatConsumptionEnum.");
            Elettrodomestico _elettrodomestico_4 = sensor.getElettrodomestico();
            Consumption _consumption_2 = _elettrodomestico_4.getConsumption();
            _builder.append(_consumption_2, "		");
            _builder.append(", 1)));");
            _builder.newLineIfNotEmpty();
          }
        }
      }
    }
    _builder.append("\t\t");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("return sensors;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("private double loadConsumFromProp(CatConsumptionEnum consumption, int minMax) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("String propString = null;");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("if(prop == null) {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("prop = new Properties();");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("try {");
    _builder.newLine();
    _builder.append("\t\t\t\t");
    _builder.append("prop.load(new FileInputStream(propertiesPath));");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("} catch (FileNotFoundException e) {");
    _builder.newLine();
    _builder.append("\t\t\t\t");
    _builder.append("e.printStackTrace();");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("} catch (IOException e) {");
    _builder.newLine();
    _builder.append("\t\t\t\t");
    _builder.append("e.printStackTrace();");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("if(consumption == CatConsumptionEnum.LOW) {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("if(minMax == 0)");
    _builder.newLine();
    _builder.append("\t\t\t\t");
    _builder.append("propString = \"minConsumoBasso\";");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("else if(minMax == 1)");
    _builder.newLine();
    _builder.append("\t\t\t\t");
    _builder.append("propString = \"maxConsumoBasso\";");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("else if(consumption == CatConsumptionEnum.MEDIUM) {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("if(minMax == 0)");
    _builder.newLine();
    _builder.append("\t\t\t\t");
    _builder.append("propString = \"minConsumoMedio\";");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("else if(minMax == 1)");
    _builder.newLine();
    _builder.append("\t\t\t\t");
    _builder.append("propString = \"maxConsumoMedio\";");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("else if(consumption == CatConsumptionEnum.HIGH) {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("if(minMax == 0)");
    _builder.newLine();
    _builder.append("\t\t\t\t");
    _builder.append("propString = \"minConsumoAlto\";");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("else if(minMax == 1)");
    _builder.newLine();
    _builder.append("\t\t\t\t");
    _builder.append("propString = \"maxConsumoAlto\";");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("if(propString != null)");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("return Double.valueOf(prop.getProperty(propString));");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("else");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("return -1;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    return _builder;
  }
  
  public StringConcatenation createElettrodomesticoInterface(final System s) {
    StringConcatenation _builder = new StringConcatenation();
    {
      Package _package = s.getPackage();
      boolean _operator_notEquals = ObjectExtensions.operator_notEquals(_package, null);
      if (_operator_notEquals) {
        _builder.append("package ");
        Package _package_1 = s.getPackage();
        String _name = _package_1.getName();
        _builder.append(_name, "");
        _builder.append(";");
        _builder.newLineIfNotEmpty();
      }
    }
    _builder.newLine();
    _builder.append("public interface IElettrodomestico");
    _builder.newLine();
    _builder.append("{");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("double getConsumption();");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("double getMediumConsumption();");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("String getNome();");
    _builder.newLine();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("StatoED getStato();");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("CatUsage getCatUso();");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("boolean powerOn( );");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("boolean powerOff( );");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("boolean swithToActive();");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    return _builder;
  }
  
  public StringConcatenation createElettrodomesticoClass(final System s) {
    StringConcatenation _builder = new StringConcatenation();
    {
      Package _package = s.getPackage();
      boolean _operator_notEquals = ObjectExtensions.operator_notEquals(_package, null);
      if (_operator_notEquals) {
        _builder.append("package ");
        Package _package_1 = s.getPackage();
        String _name = _package_1.getName();
        _builder.append(_name, "");
        _builder.append(";");
        _builder.newLineIfNotEmpty();
      }
    }
    _builder.newLine();
    _builder.append("import java.util.Properties;");
    _builder.newLine();
    _builder.newLine();
    _builder.append("public class Elettrodomestico implements IElettrodomestico");
    _builder.newLine();
    _builder.append("{");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("private String nome;\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("private StatoED stato;\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("private CatUsage catUso;\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("private CatConsumption catConsumption;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("private double consumoAttuale;");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public Elettrodomestico() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("this(\"\", CatUsage.OPTIONAL, CatConsumptionEnum.LOW);");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public Elettrodomestico(String nome, CatUsage catUso, CatConsumptionEnum catConsumption) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("this.nome = nome;");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("this.catUso = catUso;");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("this.catConsumption = CatConsumption.getCatConsumption(catConsumption);");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("this.stato = StatoED.OFF;");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("this.consumoAttuale = 0;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public Elettrodomestico(String nome, CatUsage catUso, CatConsumptionEnum catConsumption, Properties prop) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("this.nome = nome;");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("this.catUso = catUso;");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("this.catConsumption = CatConsumption.getCatConsumption(catConsumption, prop);");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("this.stato = StatoED.OFF;");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("this.consumoAttuale = 0;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public String getNome() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("return nome;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public StatoED getStato() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("return stato;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public CatUsage getCatUso() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("return catUso;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public CatConsumptionEnum getCatConsumptionEnum() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("return catConsumption.getCatConsumptionEnum();");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public CatConsumption getCatConsumption() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("return catConsumption;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public synchronized double getConsumption() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("return consumoAttuale;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public synchronized void setConsumoAttuale(double consumoAttuale) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("if(consumoAttuale >= 0)");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("this.consumoAttuale = consumoAttuale;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("@Override");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public boolean powerOn() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("stato = StatoED.CONDITIONED;\t");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("return true;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("@Override");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public boolean powerOff() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("stato = StatoED.OFF;");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("setConsumoAttuale(0);");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("return true;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public double getMediumConsumption() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("return (catConsumption.getMinConsumption() + catConsumption.getMaxConsumption()) / 2;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public void setStato(StatoED stato) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("this.stato = stato;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("@Override");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public boolean equals(Object obj) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("if (this == obj)");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("return true;");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("if (obj == null)");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("return false;");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("if (getClass() != obj.getClass())");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("return false;");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("Elettrodomestico other = (Elettrodomestico) obj;");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("if (catConsumption.getCatConsumptionEnum() != other.catConsumption.getCatConsumptionEnum())");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("return false;");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("if (catUso != other.catUso)");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("return false;");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("if (Double.doubleToLongBits(consumoAttuale) != Double.doubleToLongBits(other.consumoAttuale))");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("return false;");
    _builder.newLine();
    _builder.append("//\t\tif (nome != other.nome)");
    _builder.newLine();
    _builder.append("//\t\t\treturn false;");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("if (stato != other.stato)");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("return false;");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("if (!nome.equals(other.nome))");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("return false;");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("return true;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public boolean equals(String name) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("return this.getNome().equals(name);");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("@Override");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public String toString() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("return nome + \"(\" + stato + \", \" + catUso + \", \" + catConsumption.getCatConsumptionEnum() + \") - \" + consumoAttuale;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("@Override");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public boolean swithToActive() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("if(stato == StatoED.CONDITIONED) {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("stato = StatoED.ACTIVE;");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("return true;");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("return false;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    return _builder;
  }
  
  public StringConcatenation createCatConsumptionClass(final System s) {
    StringConcatenation _builder = new StringConcatenation();
    {
      Package _package = s.getPackage();
      boolean _operator_notEquals = ObjectExtensions.operator_notEquals(_package, null);
      if (_operator_notEquals) {
        _builder.append("package ");
        Package _package_1 = s.getPackage();
        String _name = _package_1.getName();
        _builder.append(_name, "");
        _builder.append(";");
        _builder.newLineIfNotEmpty();
      }
    }
    _builder.newLine();
    _builder.append("import java.io.FileInputStream;");
    _builder.newLine();
    _builder.append("import java.io.FileNotFoundException;");
    _builder.newLine();
    _builder.append("import java.io.IOException;");
    _builder.newLine();
    _builder.append("import java.util.Properties;");
    _builder.newLine();
    _builder.newLine();
    _builder.append("public class CatConsumption {");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("private CatConsumptionEnum catConsumption;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("private double minConsumption;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("private double maxConsumption;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("private static final String propertiesPath = \"G:\\\\Documenti\\\\Universita\\\\Magistrale\\\\Ingegneria dei Sistemi Software M\\\\workspace\\\\domotica.scontrol\\\\src\\\\system.properties\";");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public CatConsumption() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("this(CatConsumptionEnum.LOW);");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public CatConsumption(CatConsumptionEnum catConsumption) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("boolean exceptionOccured = false;");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("this.catConsumption = catConsumption;");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("Properties prop = new Properties();");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("try {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("prop.load(new FileInputStream(propertiesPath));");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("} catch (FileNotFoundException e) {");
    _builder.newLine();
    _builder.append("//\t\t\te.printStackTrace();");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("exceptionOccured = true;");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("loadDefaultValues();");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("} catch (IOException e) {");
    _builder.newLine();
    _builder.append("//\t\t\te.printStackTrace();");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("exceptionOccured = true;");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("loadDefaultValues();");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("if(!exceptionOccured)");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("loadValuesFromProperties(prop);");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public CatConsumption(CatConsumptionEnum catConsumption, Properties prop) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("this.catConsumption = catConsumption;");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("if(prop == null) {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("loadDefaultValues();");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("else {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("loadValuesFromProperties(prop);");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public double getMinConsumption() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("return minConsumption;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public double getMaxConsumption() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("return maxConsumption;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("private void loadDefaultValues() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("if(catConsumption == CatConsumptionEnum.LOW) {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("minConsumption = 1;");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("maxConsumption = 500;");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("else if(catConsumption == CatConsumptionEnum.MEDIUM) {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("minConsumption = 501;");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("maxConsumption = 1000;");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("else if(catConsumption == CatConsumptionEnum.HIGH) {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("minConsumption = 1001;");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("maxConsumption = 2000;");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("private void loadValuesFromProperties(Properties prop) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("if(catConsumption == CatConsumptionEnum.LOW) {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("minConsumption = Double.valueOf(prop.getProperty(\"minConsumoBasso\"));");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("maxConsumption = Double.valueOf(prop.getProperty(\"maxConsumoBasso\"));");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("else if(catConsumption == CatConsumptionEnum.MEDIUM) {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("minConsumption = Double.valueOf(prop.getProperty(\"minConsumoMedio\"));");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("maxConsumption = Double.valueOf(prop.getProperty(\"maxConsumoMedio\"));");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("else if(catConsumption == CatConsumptionEnum.HIGH) {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("minConsumption = Double.valueOf(prop.getProperty(\"minConsumoAlto\"));");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("maxConsumption = Double.valueOf(prop.getProperty(\"maxConsumoAlto\"));");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public static CatConsumption getCatConsumption(CatConsumptionEnum cat) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("return new CatConsumption(cat);");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public static CatConsumption getCatConsumption(CatConsumptionEnum cat, Properties prop) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("return new CatConsumption(cat, prop);");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public CatConsumptionEnum getCatConsumptionEnum() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("return catConsumption;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    return _builder;
  }
  
  public StringConcatenation createCatConsumptionEnum(final System s) {
    StringConcatenation _builder = new StringConcatenation();
    {
      Package _package = s.getPackage();
      boolean _operator_notEquals = ObjectExtensions.operator_notEquals(_package, null);
      if (_operator_notEquals) {
        _builder.append("package ");
        Package _package_1 = s.getPackage();
        String _name = _package_1.getName();
        _builder.append(_name, "");
        _builder.append(";");
        _builder.newLineIfNotEmpty();
      }
    }
    _builder.newLine();
    _builder.append("public enum CatConsumptionEnum");
    _builder.newLine();
    _builder.append("{");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("LOW, MEDIUM, HIGH;");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    return _builder;
  }
  
  public StringConcatenation createCatUsage(final System s) {
    StringConcatenation _builder = new StringConcatenation();
    {
      Package _package = s.getPackage();
      boolean _operator_notEquals = ObjectExtensions.operator_notEquals(_package, null);
      if (_operator_notEquals) {
        _builder.append("package ");
        Package _package_1 = s.getPackage();
        String _name = _package_1.getName();
        _builder.append(_name, "");
        _builder.append(";");
        _builder.newLineIfNotEmpty();
      }
    }
    _builder.newLine();
    _builder.append("public enum CatUsage");
    _builder.newLine();
    _builder.append("{");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("OPTIONAL, ESSENTIAL;");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    return _builder;
  }
  
  public StringConcatenation createStatoEDEnum(final System s) {
    StringConcatenation _builder = new StringConcatenation();
    {
      Package _package = s.getPackage();
      boolean _operator_notEquals = ObjectExtensions.operator_notEquals(_package, null);
      if (_operator_notEquals) {
        _builder.append("package ");
        Package _package_1 = s.getPackage();
        String _name = _package_1.getName();
        _builder.append(_name, "");
        _builder.append(";");
        _builder.newLineIfNotEmpty();
      }
    }
    _builder.newLine();
    _builder.append("public enum StatoED {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("OFF, CONDITIONED, ACTIVE;");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    return _builder;
  }
  
  public StringConcatenation createSensorInterface(final System s) {
    StringConcatenation _builder = new StringConcatenation();
    {
      Package _package = s.getPackage();
      boolean _operator_notEquals = ObjectExtensions.operator_notEquals(_package, null);
      if (_operator_notEquals) {
        _builder.append("package ");
        Package _package_1 = s.getPackage();
        String _name = _package_1.getName();
        _builder.append(_name, "");
        _builder.append(";");
        _builder.newLineIfNotEmpty();
      }
    }
    _builder.newLine();
    _builder.append("public interface ISensor {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public String getEdName();");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public double getConsumption();");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    return _builder;
  }
  
  public StringConcatenation createSensorClass(final System s) {
    StringConcatenation _builder = new StringConcatenation();
    {
      Package _package = s.getPackage();
      boolean _operator_notEquals = ObjectExtensions.operator_notEquals(_package, null);
      if (_operator_notEquals) {
        _builder.append("\t");
        _builder.append("package ");
        Package _package_1 = s.getPackage();
        String _name = _package_1.getName();
        _builder.append(_name, "	");
        _builder.append(";");
        _builder.newLineIfNotEmpty();
      }
    }
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public class Sensor implements ISensor {");
    _builder.newLine();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("private double minCons;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("private double maxCons;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("private double firstConsumption = -1;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("private String edName;");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public Sensor() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("this(\"\", 1.0, 500.0);");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public Sensor(String edName) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("this(edName, 1.0, 500.0);");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public Sensor(double minCons, double maxCons) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("this(\"\", minCons, maxCons);");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public Sensor(String edName, double minCons, double maxCons) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("this.edName = edName;");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("this.minCons = minCons;");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("this.maxCons = maxCons;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public String getEdName() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("return edName;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public void setEdName(String edName) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("this.edName = edName;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public double getConsumption() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("double consumption = -1;");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("if(minCons == maxCons)");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("return maxCons;");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("if(firstConsumption == -1) {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("while(consumption < minCons || consumption > maxCons) {");
    _builder.newLine();
    _builder.append("\t\t\t\t");
    _builder.append("consumption = Math.random() * maxCons;");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("firstConsumption = consumption;");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("else {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("// Varia di poco il consumo precedente per essere pi\u00F9 realistico");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("while(consumption < minCons || consumption < (firstConsumption-1) ");
    _builder.newLine();
    _builder.append("\t\t\t\t\t");
    _builder.append("|| (consumption > firstConsumption+1) || consumption > maxCons) {");
    _builder.newLine();
    _builder.append("\t\t\t\t");
    _builder.append("consumption = Math.random() * (firstConsumption+1);");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("return consumption;");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.newLine();
    return _builder;
  }
}